package com.zlzlib.manager.config;

import com.zlzlib.common.bean.BooleanEnum;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @DateTime: 2024/7/31 10:24
 * @Author zlz
 * @Version 1.0
 */
public abstract class BaseMyTypeHandler<T> extends BaseTypeHandler<T> {

    @Override
    public T getNullableResult(ResultSet rs, String columnName) throws SQLException {
        String value = rs.getString(columnName);
        return parseValue(value);
    }

    @Override
    public T getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        String value = rs.getString(columnIndex);
        return parseValue(value);
    }

    @Override
    public T getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        String value = cs.getString(columnIndex);
        return parseValue(value);
    }

    protected abstract T parseValue(String value);
}
